import * as NS from '../../../Common/NetServices';
import { IsNull } from '../../../TYLibrary/Common/GlobalExtend';
import { Log } from '../../../TYLibrary/System/Logger';
import { Wx_PageData, WXDataClassRuntimeDecorator } from '../../../Common/EntityBase';
import { Wx_XSPPage } from '../../../Common/Entitys';

@WXDataClassRuntimeDecorator()
class IndexPageData extends Wx_PageData {
    public winHeight: string = "";
    public scrollHeight: number = 0;
    public currentTab: number = 0;
    public scrollLeft: number = 0;
    public sedindex: number = 0;
    public priceTopColor: string = "#000";
    public priceBotColor: string = "#000";
}

class IndexPage extends Wx_XSPPage {
    public Data: IndexPageData = new IndexPageData();

    /**
     * 初始化页面信息
     * @param {any} options
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async InitData(options:any): Promise<void> {
        this.EditTabBar2();
        console.info("res.windowHeight");
        wx.getSystemInfo({
            success: res => {
                console.info(res.windowHeight);
                this.Data.scrollHeight = res.windowHeight;
                this.Data.ApplyChange(this);
            }
        });
    }

    /**
     * 滚动切换标签样式
     * @param {e} any
     * @returns {void}
     * @memberof IndexPage
     */
    public switchTab(e: any): void {
        this.Data.currentTab = e.detail.current;
        this.Data.ApplyChange(this);
    }

    /**
     * 点击标题切换当前页时改变样式
     * @param {e} any
     * @returns {boolean}
     * @memberof IndexPage
     */
    public swichNavHandler(e: any): boolean {
        var cur = e.target.dataset.current;
        if (this.Data.currentTab == cur) {
            return false;
        } else {
            this.Data.currentTab = cur;
            this.Data.ApplyChange(this);
        }
        // this.checkCor();
        this.Data.scrollLeft = cur * 50 + 10;
        this.Data.ApplyChange(this);
    }

    /**
     * 判断当前滚动超过一屏时，设置tab标题滚动条。
     * @returns {void}
     * @memberof IndexPage
     */
    public checkCor(): void {
        if (this.Data.currentTab >= 3) {
            this.Data.scrollLeft = 200;
        } else {
            this.Data.scrollLeft = 0;
        }
        this.Data.ApplyChange(this);
    }

    /**
     * 
     * @param {*} e
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async scrolltolower(e: any): Promise<void> { }

    /**
     * 
     * @param {*} e
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async ShowSedHandler(e: any): Promise<void> {
        let sedindex = e.currentTarget.dataset.sedindex;
        this.Data.sedindex = sedindex;
        this.Data.ApplyChange(this);
    }

    /**
     * 
     * @param {*} e
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async  priceTopHandler(e: any): Promise<void> {
        if (this.Data.priceBotColor != "#000")
            this.Data.priceBotColor = "#000";
        if (this.Data.priceTopColor == "#e32323") {
            this.Data.priceTopColor = "#000";
            await this.Data.ApplyChange(this);
        } else {
            this.Data.priceTopColor = '#e32323';
            await this.Data.ApplyChange(this);
        }
    }
    /**
     * 
     * @param {*} e
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async priceBottomHandler(e: any): Promise<void> {
        if (this.Data.priceTopColor != "#000")
            this.Data.priceTopColor = "#000";
        if (this.Data.priceBotColor == "#e32323") {
            this.Data.priceBotColor = "#000";
            await this.Data.ApplyChange(this);
        } else {
            this.Data.priceBotColor = '#e32323';
            await this.Data.ApplyChange(this);
        }
    }
}

Page(new IndexPage());
